/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package its.serviceSystem.Bean;

import java.math.BigDecimal;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.its.dds2.ServicesSystem.Modelo.Typeclass;
import mx.its.dds2.serviceSystem.Bl.TypeClassLocal;

/**
 *
 * @author Carlos Asis
 */
@ManagedBean
@SessionScoped
public class TypeClassBean {
    @EJB
    private TypeClassLocal typeClass;

    
    
    /**
     * Creates a new instance of TypeClassBean
     */
    public TypeClassBean() {
        type=new Typeclass();
    }
    private Typeclass type;
    private List<Typeclass> listTypeclass;
    private int b = 0;

    public Typeclass getTypeclass() {
        return type;
    }

    public void setTypeclass(Typeclass type) {
        this.type = type;
    }

    public List<Typeclass> getTypeclasss() {
        listTypeclass = typeClass.getListAll();
        return listTypeclass;
    }

    public void setTypeclasss(List<Typeclass> listTypeclass) {
        this.listTypeclass = listTypeclass;
    }

    public String prepararNuevo() {
        b = 1;
        type = new Typeclass();
        
        return "TypeClassCrearEditar";
    }

    public String prepararNuevoFace() {
        b = 1;
        type = new Typeclass();
        return "TypeClassCrearEditar";
    }

    public void prepararEditar(ActionEvent a) {
        b = 2;
        String cId = a.getComponent().getClientId().split(":")[2];
        int id = Integer.parseInt(cId);
        type = listTypeclass.get(id);
    }

    public String guardar() {
        switch (b) {
            case 1:
                typeClass.register(type);
                break;
            case 2:
                typeClass.modify(type);
                break;
            case 3:
            // typeClass.r(type);
        }
        return "TypeClassFacelets";
    }

    public void eliminar(ActionEvent a) {
        b = 3;
        String cId = a.getComponent().getClientId().split(":")[2];
        int id = Integer.parseInt(cId);
        type = listTypeclass.get(id);
        guardar();
    }
}
